package com.zzptc.mzb.statisticaltable;

import android.content.Context;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;


public class SecondFragment2 extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_second_fragment2, container, false);

       BarChart bar = view.findViewById(R.id.barChat);
       //建立集合
        List<BarEntry> barList=new ArrayList<>();
        List<BarEntry> mbarList=new ArrayList<>();
        for (int i=0;i<10;i++){
            barList.add(new BarEntry(i,new Random().nextInt(10)));
           mbarList.add(new BarEntry(i,new Random().nextInt(15)));
        }
        BarDataSet barDataSet=new BarDataSet(barList,"男");
        barDataSet.setColor(Color.BLUE);
        BarDataSet barDataSet1 = new BarDataSet(mbarList, "女");
        barDataSet1.setColor(Color.RED);
        BarData barData=new BarData(barDataSet);
       barData.addDataSet(barDataSet1);
        bar.setData(barData);

        bar.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
        bar.getAxisRight().setEnabled(false);
        bar.groupBars(1,0.6f,0);
        barData.setBarWidth(0.2f);
        bar.getXAxis().setAxisMinimum(1);
        bar.getXAxis().setAxisMaximum(8);
        bar.getXAxis().setLabelCount(5, false);
        bar.getXAxis().setCenterAxisLabels(true);
        // Inflate the layout for this fragment
        return view;
    }
}
